From: Philip Chimento Date: Tue, 29 Oct 2019 00:06:40 +0000 (-0700) Subject: mpris: Validate received data against the expected types from the spec X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~781^2^2~488 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=975280fc50651bd67c3551840cf3026b2d75a33b;p=gnome-shell.git mpris: Validate received data against the expected types from the spec In the wild we have buggy clients (notably Chromium 77 and earlier) that send metadata with the wrong types. Previously, this would throw an exception and prevent the MPRIS information from showing up in the message list. This changes the code to check if any incoming metadata is of the type it is expected to be, and logs a warning if not, then continues on with a default value. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1362 --- diff --git a/js/ui/mpris.js b/js/ui/mpris.js index c46f9f01c..240e99e5f 100644 --- a/js/ui/mpris.js +++ b/js/ui/mpris.js @@ -95,6 +95,7 @@ var MprisPlayer = class MprisPlayer { this._trackArtists = []; this._trackTitle = ''; this._trackCoverUrl = ''; + this._busName = busName; } get status() { @@ -177,9 +178,36 @@ var MprisPlayer = class MprisPlayer { for (let prop in this._playerProxy.Metadata) metadata[prop] = this._playerProxy.Metadata[prop].deep_unpack(); - this._trackArtists = metadata['xesam:artist'] || [_("Unknown artist")]; - this._trackTitle = metadata['xesam:title'] || _("Unknown title"); - this._trackCoverUrl = metadata['mpris:artUrl'] || ''; + // Validate according to the spec; some clients send buggy metadata: + // https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata + this._trackArtists = metadata['xesam:artist']; + if (!Array.isArray(this._trackArtists) || + !this._trackArtists.every(artist => typeof artist === 'string')) { + if (typeof this._trackArtists !== 'undefined') + log(`Received faulty track artist metadata from ${ + this._busName}; expected an array of strings, got ${ + this._trackArtists} (${typeof this._trackArtists})`); + this._trackArtists = [_("Unknown artist")]; + } + + this._trackTitle = metadata['xesam:title']; + if (typeof this._trackTitle !== 'string') { + if (typeof this._trackTitle !== 'undefined') + log(`Received faulty track title metadata from ${ + this._busName}; expected a string, got ${ + this._trackTitle} (${typeof this._trackTitle})`); + this._trackTitle = _("Unknown title"); + } + + this._trackCoverUrl = metadata['mpris:artUrl']; + if (typeof this._trackCoverUrl !== 'string') { + if (typeof this._trackCoverUrl !== 'undefined') + log(`Received faulty track cover art metadata from ${ + this._busName}; expected a string, got ${ + this._trackCoverUrl} (${typeof this._trackCoverUrl})`); + this._trackCoverUrl = ''; + } + this.emit('changed'); let visible = this._playerProxy.CanPlay;